<?php
/**
 * Created by PhpStorm.
 * User: js
 * Date: 2018/10/10
 * Time: 11:49
 */

namespace app\modules\api\models;


use app\models\LiveIndex;

class OpenLiveForm extends Model
{

    public $status;
    public $wechat_app_id;
    public $begin_time;
    public $end_time;

    public function rules()
    {
        return [
            [['status','wechat_app_id',], 'required',],
        ];
    }

    public function save()
    {
        if (!$this->validate())
            return $this->getModelError();
//        $begin_time = \yii::$app ->request ->get('begin_time');
//        $end_time = \yii::$app ->request ->get('end_time');
//        if($begin_time && $end_time){
//            $res = LiveIndex::updateAll(['status' => 1,'begin_time'=>$begin_time,'end_time'=>$end_time], [
//                'wechat_app_id' => \yii::$app->request->get('wechat_app_id'),
//            ]);
//        }elseif($begin_time && $end_time==''){
//            $res = LiveIndex::updateAll(['status' => 1,'begin_time'=>$begin_time], [
//                'wechat_app_id' => \yii::$app->request->get('wechat_app_id'),
//            ]);
//        }elseif (!$begin_time && $end_time){
//            $res = LiveIndex::updateAll(['status' => 1,'end_time'=>$end_time], [
//                'wechat_app_id' => \yii::$app->request->get('wechat_app_id'),
//            ]);
//        }else{
        $state = \yii::$app->request->get('status');
            $res = LiveIndex::updateAll(['status' => $state], [
                'wechat_app_id' => \yii::$app->request->get('wechat_app_id'),
            ]);
//        }
        if ($res)
            return [
                'code' => 0,
                'msg' => 'success',
            ];
        else
            return [
                'code' => 1,
                'msg' => 'fail',
            ];
    }

}